﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetPageFTradeSaleTypeConfig.aspx.cs" Inherits="IHISCETeim.Web.MachineSys.FTradeModel.GetPageFTradeSaleTypeConfig" %>
<%--2013-07-13 自定义收款条款 配置--%>
<div id="<%=globalTag %>_SaleTypeConfig_Type_Div" style=" clear:both; border-bottom:2px solid #000; line-height:25px; ">
    自定义收款组合： 
    <input type="checkbox" name="SaleTypeConfig_Type" value="一般销售" id="<%=globalTag %>_SaleTypeConfig_Type1"  SaleTypeConfigId="1" class="SaleTypeConfig_Type" />
    <label for="<%=globalTag %>_SaleTypeConfig_Type1" style=" float:none!important;">1.一般销售</label>    
    <input type="checkbox" name="SaleTypeConfig_Type" value="置换" id="<%=globalTag %>_SaleTypeConfig_Type3"  SaleTypeConfigId="3" class="SaleTypeConfig_Type"/>
    <label for="<%=globalTag %>_SaleTypeConfig_Type3" style=" float:none!important;">2.置换</label>
    <input type="checkbox" name="SaleTypeConfig_Type" value="首付代垫" id="<%=globalTag %>_SaleTypeConfig_Type4"  SaleTypeConfigId="4" class="SaleTypeConfig_Type"/>
    <label for="<%=globalTag %>_SaleTypeConfig_Type4" style=" float:none!important;">3.首付代垫</label>
    <input type="checkbox" name="SaleTypeConfig_Type" value="分期" id="<%=globalTag %>_SaleTypeConfig_Type2"  SaleTypeConfigId="2" class="SaleTypeConfig_Type"/>
    <label for="<%=globalTag %>_SaleTypeConfig_Type2" style=" float:none!important;">4.分期</label>
</div>

<div style=" clear:both;">
   <div id="<%=globalTag %>_SaleTypeConfig_Type1_Con" style="display:none; padding-left:5px; border-bottom:1px solid #B8D0D6;">
        <b style="clear:both; line-height:25px;">一般销售：</b>
        <div class="SaleTypeConfig_TempCon ">
            <p>
               <input type="text" name="Page_ShowTitle" value="金额" size="10" style=" float:none!important;"/>：
               <input name="Page_JinE" class="required inputFloat" type="text" value="0" size=""alt=""  style=" float:none!important;"/><span class="unit">元</span>
            </p>
            <p>
                <label style=" float:none!important;">到期日：</label>
                <input name="Page_DaoQiRi" class="date" type="text" value="" size="" alt="" style=" float:none!important;"/>
                <span class="SaleTypeConfi_OpCon"><a href="javascript:none;">&nbsp;&nbsp;+新&nbsp;增+&nbsp;&nbsp;</a></span>
            </p>
            <input type="hidden" name="Page_ShowIndex" value="0" />
            <input type="hidden" name="Page_TongJiName" value="一般销售" />
           <%-- <input type="hidden" name="Page_ShowTitle" value="金额1" />--%>
            <input type="hidden" name="Page_SuspendedMark" value="0" />
           <div class="divider"></div>
        </div>        
   </div>

   <div id="<%=globalTag %>_SaleTypeConfig_Type3_Con" style="display:none; padding-left:5px; border-bottom:1px solid #B8D0D6;">
        <b style="clear:both; line-height:25px;">置换：</b>        
        <div>
             <p>
               <input type="text" name="Page_ShowTitle" value="置换金额" size="10" style=" float:none!important;"/>：
               <input name="Page_JinE" class="required inputFloat" type="text" value="0" size=""alt=""  style=" float:none!important;"/><span class="unit">元</span>
            </p>
            <p>
                <label style=" float:none!important;">到期日：</label>
                <input name="Page_DaoQiRi" class="date" type="text" value="" size="" alt="" style=" float:none!important;"/>                
            </p>
            <input type="hidden" name="Page_ShowIndex" value="0" />
            <input type="hidden" name="Page_TongJiName" value="置换分期" />
           <%-- <input type="hidden" name="Page_ShowTitle" value="金额1" />--%>
            <input type="hidden" name="Page_SuspendedMark" value="0" />
           <div class="divider"></div>
        </div>   
         <div class="SaleTypeConfig_TempCon ">
            <p>
               <input type="text" name="Page_ShowTitle" readonly  value="首付金额" size="10" style=" float:none!important;"/>：
               <input name="Page_JinE" class="required inputFloat" type="text" value="0" size=""alt=""  style=" float:none!important;"/><span class="unit">元</span>
            </p>
            <p>
                <label style=" float:none!important;">到期日：</label>
                <input name="Page_DaoQiRi" class="date" type="text" value="" size="" alt="" style=" float:none!important;"/>
                <span class="SaleTypeConfi_OpCon"><a href="javascript:none;">&nbsp;&nbsp;+新&nbsp;增+&nbsp;&nbsp;</a></span>
            </p>
            <input type="hidden" name="Page_ShowIndex" value="1" />
            <input type="hidden" name="Page_TongJiName" value="一般销售" />
           <%-- <input type="hidden" name="Page_ShowTitle" value="金额1" />--%>
            <input type="hidden" name="Page_SuspendedMark" value="0" />
           <div class="divider"></div>
        </div>    
   </div>

   <div id="<%=globalTag %>_SaleTypeConfig_Type4_Con" style="display:none; padding-left:5px; border-bottom:1px solid #B8D0D6;">
        <b style="clear:both; line-height:25px;">首付代垫：</b>
        
        <div>
             <p>
               <input type="text" name="Page_ShowTitle" value="代垫金额" size="10" style=" float:none!important;"/>：
               <input name="Page_JinE" class="required inputFloat" type="text" value="0" size=""alt=""  style=" float:none!important;"/><span class="unit">元</span>
            </p>
            <p>
                <label style=" float:none!important;">到期日：</label>
                <input name="Page_DaoQiRi" class="date" type="text" value="" size="" alt="" style=" float:none!important;"/>                
            </p>
            <input type="hidden" name="Page_ShowIndex" value="0" />
            <input type="hidden" name="Page_TongJiName" value="首付代垫" />
           <%-- <input type="hidden" name="Page_ShowTitle" value="金额1" />--%>
            <input type="hidden" name="Page_SuspendedMark" value="0" />
           <div class="divider"></div>
        </div>   
        <div class="SaleTypeConfig_TempCon ">
            <p>
               <input type="text" name="Page_ShowTitle" readonly value="首付金额" size="10" style=" float:none!important;"/>：
               <input name="Page_JinE" class="required inputFloat" type="text" value="0" size=""alt=""  style=" float:none!important;"/><span class="unit">元</span>
            </p>
            <p>
                <label style=" float:none!important;">到期日：</label>
                <input name="Page_DaoQiRi" class="date" type="text" value="" size="" alt="" style=" float:none!important;"/>
                <span class="SaleTypeConfi_OpCon"><a href="javascript:none;">&nbsp;&nbsp;+新&nbsp;增+&nbsp;&nbsp;</a></span>
            </p>
            <input type="hidden" name="Page_ShowIndex" value="1" />
            <input type="hidden" name="Page_TongJiName" value="一般销售" />
           <%-- <input type="hidden" name="Page_ShowTitle" value="金额1" />--%>
            <input type="hidden" name="Page_SuspendedMark" value="0" />
           <div class="divider"></div>
        </div>     
   </div>

   <div id="<%=globalTag %>_SaleTypeConfig_Type2_Con" style="display:none; padding-left:5px; border-bottom:1px solid #B8D0D6;">
        <b style="clear:both; line-height:25px;">分期：</b>
        <div class="SaleTypeConfig_TempCon">
            <p>
               <input type="text" name="Page_ShowTitle" readonly  value="首付金额" size="10" style=" float:none!important;"/>：
               <input name="Page_JinE" class="required inputFloat type2coninput" type="text" value="0" style=" float:none!important;"/><span class="unit">元</span>
            </p>
            <p>
                <label style=" float:none!important;">到期日：</label>
                <input name="Page_DaoQiRi" class="date" type="text" style=" float:none!important;" id="<%=globalTag %>_SaleTypeConfig_Type2_DaoQiRi"/>
                <span class="SaleTypeConfi_OpCon"><a href="javascript:none;">&nbsp;&nbsp;+新&nbsp;增+&nbsp;&nbsp;</a></span>
            </p>
            <input type="hidden" name="Page_ShowIndex" value="0" />
            <input type="hidden" name="Page_TongJiName" value="短期分期" />
           <%-- <input type="hidden" name="Page_ShowTitle" value="金额1" />--%>
            <input type="hidden" name="Page_SuspendedMark" value="0" />
            <div class="divider"></div>
        </div>     
        
        <div >
            配置分期参数:<br/>
            <p>
                <input type="text"  size="10" value="2.期数" readonly style=" float:none!important;"/>：
                <input id="<%=globalTag %>_SaleTypeConfig_Type2_QiShu" name="PageConfig_QiShu"  class="required inputFloat" type="text" value="0" min=0 max=36 style=" float:none!important;" />
                <select id="<%=globalTag %>_SaleTypeConfig_Type2_QiShuType" name="PageConfig_QiShuType" style=" float:none!important;">
                    <option value="m" selected>月</option>
                    <option value="q">季</option>
                    <option value="f">期</option>
                </select>
            </p>
            <p>
                <label style=" float:none!important;">每期金额：</label>
                <input id="<%=globalTag %>_SaleTypeConfig_Type2_JinE" name="PageConfig_JinE" class="required inputFloat" type="text" value="0" style=" float:none!important;" />
                <span class="unit">元</span>
            </p>
            <div class="divider"></div>
        </div>
        <div id="<%=globalTag %>_Page_AutoFenQiCon">
            <%--自动根据以上参数自动生成分期信息--%>
        </div>
   </div>

</div>

<script  type="text/javascript">

    $(document).ready(function () {
        var globalTag = "<%=globalTag %>"; //来源标记，用于ID，防止打开两个页面有相同的ID标记
        $("#" + globalTag + "_SaleTypeConfig_Type_Div input.SaleTypeConfig_Type").click(function () {
            return false;
            //SaleTypeConfigCheckClick($(this));
            //

        })
        //分期输入分期金额后，处理每期数据
        $("#" + globalTag + "_SaleTypeConfig_Type2_JinE,#" + globalTag + "_SaleTypeConfig_Type2_QiShu,#" + globalTag + "_SaleTypeConfig_Type2_QiShuType").blur(function () {
            //3.起始日期
            var lastDaoQiRi = $("#" + globalTag + "_SaleTypeConfig_Type2_DaoQiRi").val();
            if (lastDaoQiRi == "") {
                alert("请先输入首付款到期日");
                return false;
            }
            // lastDaoQiRi = new Date(lastDaoQiRi);
            $("#" + globalTag + "_Page_AutoFenQiCon").empty();
            //1.期数
            var qishu = parseInt($("#" + globalTag + "_SaleTypeConfig_Type2_QiShu").val());
            if (qishu > 36) {
                alert("期数值不能大于36，请重输");
                $("#" + globalTag + "_SaleTypeConfig_Type2_QiShu").val("0");
                return false;
            }
            //2.每期金额
            var JinE = $("#" + globalTag + "_SaleTypeConfig_Type2_JinE").val();
            //3.起始日期
            // var lastDaoQiRi = $("#" + globalTag + "_SaleTypeConfig_Type2_DaoQiRi").val();
            //4.期数按月或按季
            var QiShuType = $("#" + globalTag + "_SaleTypeConfig_Type2_QiShuType").val();

            var htmltag = "<p>" +
		                        "   <input type='text' name='Page_ShowTitle' size='10' value='分期-标记' style='float:none!important;'/>:" +
		                        "   <input name='Page_JinE' class='required inputFloat' type='text' value='-金额' style='float:none!important;' />" +
                                "   <span class='unit'>元</span>" +
	                            "</p>" +
                                "<p>" +
		                        "    <label style='float:none!important;'>到期日：</label>" +
		                        "    <input  name='Page_DaoQiRi' class='required date' type='text' value='-时间' style='float:none!important;'/>" +
	                            "</p>" +
                                "<input type='hidden' name='Page_ShowIndex' value='-标记' />" +
                                "<input type='hidden' name='Page_TongJiName' value='短期分期' />" +
                                "<input type='hidden' name='Page_SuspendedMark' value='0' /><div style='clear:both;'></div>";
            var rowCon = "";

            for (var rowIndex = 1; rowIndex <= qishu; rowIndex++) {
                //到期日处理
                var addindex = QiShuType == "m" ? 1 : QiShuType == "q"? 3:4;
                var newyear = lastDaoQiRi.split("-")[0];
                var newmonth = lastDaoQiRi.split("-")[1];
                var newday = lastDaoQiRi.split("-")[2];
                var newDate = AddMonth(newyear, newmonth, newday, addindex);

                rowCon = htmltag.replace(/-标记/gi, rowIndex).replace(/-金额/gi, JinE).replace(/-时间/gi, newDate);

                $(rowCon).appendTo("#" + globalTag + "_Page_AutoFenQiCon");

                lastDaoQiRi = newDate;
            }
            $("#" + globalTag + "_Page_AutoFenQiCon").find("input.inputFloat").inputFloat().closest("div").find("input.date").each(function () {
                var $this = $(this);
                var opts = {};
                if ($this.attr("format")) opts.pattern = $this.attr("format");
                if ($this.attr("yearstart")) opts.yearstart = $this.attr("yearstart");
                if ($this.attr("yearend")) opts.yearend = $this.attr("yearend");
                $this.datepicker(opts);
            });

        })

        //设置默认选中项：
        var $checkSaleTypeConfigIds = "<%=GetCheckSaleTypeConfigIds() %>";
        $("#" + globalTag + "_SaleTypeConfig_Type_Div input.SaleTypeConfig_Type").each(function () {
            var $tempid = $(this).attr("SaleTypeConfigId");
            for (var tindex = 0; tindex < $checkSaleTypeConfigIds.split(",").length; tindex++) {
                if ($tempid == $checkSaleTypeConfigIds.split(",")[tindex]) {
                    //alert($tempid)
                    $(this).attr("checked", true);
                    SaleTypeConfigCheckClick($(this));
                }
            }
        })

        function SaleTypeConfigCheckClick(jobj) {

            var $SaleTypeConfigId = jobj.attr("SaleTypeConfigId");
            var $checked = jobj.attr("checked");
            var $SaleTypeConfigTypeConId = globalTag + "_SaleTypeConfig_Type" + $SaleTypeConfigId + "_Con";
            if ($checked) {
                $("#" + $SaleTypeConfigTypeConId).show().find(".SaleTypeConfi_OpCon").find("a").bind("click", function () {
                    SaleTypeConfig_TempConAdd($(this), $SaleTypeConfigId);
                    return false;
                });
               
                //处理分期中首付输入不能用.
                if ($SaleTypeConfigId == "1" || $SaleTypeConfigId == "3" || $SaleTypeConfigId == "4") {
                    //$("#" + globalTag + "_SaleTypeConfig_Type2_Con").find("input.type2coninput").val("0").attr("readonly", "readonly")
                    // $("#" + globalTag + "_SaleTypeConfig_Type2_Con").find("a").hide();
                    //$("#" + globalTag + "_SaleTypeConfig_Type2_Con").find("div.SaleTypeConfig_TempCon_Item").remove(); //移除已添加自定义项

                    //var $cloneCon = $("#" + globalTag + "_SaleTypeConfig_Type" + $SaleTypeConfigId + "_Con").find("div.SaleTypeConfig_TempCon")
                    //$cloneCon.find("input[name='Page_TongJiName']").val("一般销售");
                    //处理置换加分期时，置换其它款项不能用.
                    if ($checkSaleTypeConfigIds.indexOf("2") > 0) {
                        //alert(2);
                        $("#" + globalTag + "_SaleTypeConfig_Type" + $SaleTypeConfigId + "_Con").find("div.SaleTypeConfig_TempCon").find("input[name='Page_Jine']").val("0").attr("readonly", "readonly")
                        $("#" + globalTag + "_SaleTypeConfig_Type" + $SaleTypeConfigId + "_Con").find("div.SaleTypeConfig_TempCon").hide();
                        //$("#" + globalTag + "_SaleTypeConfig_Type" + $SaleTypeConfigId + "_Con").find("div.SaleTypeConfig_TempCon_Item").remove(); //移除已添加自定义项

                    }
                }

            } else {
                //                $("#" + $SaleTypeConfigTypeConId).hide().find(".SaleTypeConfi_OpCon").find("a").unbind("click");
                //                $("#" + $SaleTypeConfigTypeConId).find("input[name='Page_JinE']").val("0");

                //                //处理分期中首付输入能用.
                //                if ($SaleTypeConfigId == "1" || $SaleTypeConfigId == "3" || $SaleTypeConfigId == "4") {
                //                    $("#" + globalTag + "_SaleTypeConfig_Type2_Con").find("input.type2coninput").removeAttr("readonly");
                //                    $("#" + globalTag + "_SaleTypeConfig_Type2_Con").find("a").show();
                //                }
            }

        }
        //新增收款项
        //传入 触发事件相应的 jquery 项
        //_SaleTypeConfigId 当前处理的内空ID，用于做特殊处理
        function SaleTypeConfig_TempConAdd($obj, _SaleTypeConfigId) {
            //处理要进行复制的内容
            var $cloneCon = $obj.closest("div").clone().addClass("SaleTypeConfig_TempCon_Item");

            $cloneCon.find(".SaleTypeConfi_OpCon").find("a").html("&nbsp;&nbsp;-删&nbsp;除-&nbsp;&nbsp;").click(function () {
                $(this).closest("div").remove();
            });
            //$cloneCon.find("input[name='Page_TongJiName']").val("一般销售");

            $cloneCon.find("input.inputFloat").inputFloat().closest("div").find("input.date").each(function () {
                var $this = $(this);
                var opts = {};
                if ($this.attr("format")) opts.pattern = $this.attr("format");
                if ($this.attr("yearstart")) opts.yearstart = $this.attr("yearstart");
                if ($this.attr("yearend")) opts.yearend = $this.attr("yearend");
                $this.datepicker(opts);
            });

            var $siblingsLength = $obj.closest("div").siblings("div.SaleTypeConfig_TempCon:last").length;
            if ($siblingsLength > 0)
                $obj.closest("div").siblings("div.SaleTypeConfig_TempCon:last").after($cloneCon);
            else
                $obj.closest("div").after($cloneCon);
        }

        //+---------------------------------------------------   
        //| 日期计算   
        //+---------------------------------------------------
        function AddMonth(year, month, day, number) {

            var nowyear = parseInt(year);
            var nowmonth = parseInt(month);
            var nowday = parseInt(day);

            var newyear = nowyear;
            var newmonth = nowmonth;
            if ((nowmonth + number) > 12) {
                newyear += 1;
                newmonth = (nowmonth + number) - 12;
            } else {
                newmonth = nowmonth + number;
            }
            return newyear + "-" + ((newmonth <= 9 ? "0" : "") + newmonth) + "-" + ((nowday <= 9 ? "0" : "") + nowday)

        }

    })

    
</script>